package com.jjyu.service.impl;

import com.jjyu.dao.RestaurantRatingMapper;
import com.jjyu.entity.RestaurantRating;
import com.jjyu.service.RestaurantRatingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RestaurantRatingServiceImpl implements RestaurantRatingService {

    @Autowired
    private RestaurantRatingMapper restaurantRatingMapper;

    @Override
    @Transactional
    public void rateRestaurant(Long userId, Long restaurantId, Double rating) {
        restaurantRatingMapper.insertRating(userId, restaurantId, rating);
    }

    @Override
    public RestaurantRating getUserRating(Long userId, Long restaurantId) {
        return restaurantRatingMapper.getRatingByUserIdAndRestaurantId(userId, restaurantId);
    }

    @Override
    @Transactional
    public void updateRating(Long userId, Long restaurantId, Double rating) {
        restaurantRatingMapper.updateRating(userId, restaurantId, rating);
    }

    @Override
    @Transactional
    public void removeRating(Long userId, Long restaurantId) {
        restaurantRatingMapper.deleteRating(userId, restaurantId);
    }
}
